import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { codeNameInfoListAll, getFilterOptions } from '/@/api/sys/menu';
import { getDictItems } from '/@/api/common/api';
import { ApiSelect } from '/@/components/Form';
import { h } from 'vue';
import { type } from '../../components/Tree/index';

export const columns: BasicColumn[] = [
    {
        title: 'guid',
        dataIndex: 'guid'
    },
    {
        title: 'tag',
        dataIndex: 'tag'
    },
    {
        title: 'path',
        dataIndex: 'path'
    },
    {
        title: 'name',
        dataIndex: 'name'
    },
    {
        title: '（1 空间节点   2设备节点   3 点位节点）',
        dataIndex: 'nodeType'
    },
    {
        title: '删除状态',
        dataIndex: 'delFlag'
    },
    {
        title: '点位分类Point type：1=AI；2=DI；3=AO；4=DO；5=Alarm。',
        dataIndex: 'pointType'
    },
    {
        title: '点位的单位',
        dataIndex: 'unit'
    },
    {
        title: 'DI/DO的取值含义。格式如：“1=开门;0=关门”。 DI/DO的取值含义。格式如：“1=开门;0=关 必须是数值型的值。',
        dataIndex: 'statusMap'
    },
    {
        title: '告警级别',
        dataIndex: 'alarmLevel'
    },
    {
        title: '告警类型',
        dataIndex: 'alarmType'
    },
    {
        title: '上传数据的时间间隔，单位秒',
        dataIndex: 'period'
    },
    {
        title: '变比',
        dataIndex: 'percentage'
    },
    {
        title: '绝对值变比',
        dataIndex: 'absValue'
    },
    {
        title: 'AO的合法控制范围。max=30。默认NULL，AO的合法控制范围。不生效。',
        dataIndex: 'aoMaxBound'
    },
    {
        title: '围 ',
        dataIndex: 'aoMinBound'
    },
    {
        title: 'parentGuid',
        dataIndex: 'parentGuid'
    },
    {
        title: '映射监测类型',
        dataIndex: 'mpPorintType'
    },
    {
        title: '信号类型',
        dataIndex: 'mpSingType'
    },
    {
        title: '标准监控信息名称',
        dataIndex: 'mpPointName'
    },
    {
        title: '映射告警信息',
        dataIndex: 'mpAlarm'
    },
    {
        title: '编码',
        dataIndex: 'mpCode'
    },
];

export const searchFormSchema: FormSchema[] = [
    {
        label: 'guid',
        field: 'guid',
        component: 'Input'
    },
    {
        label: 'tag',
        field: 'tag',
        component: 'Input'
    },
];

export const formSchema: FormSchema[] = [
    { label: '', field: 'id', component: 'Input', show: false },
    { label: '', field: 'type', component: 'Input', show: false },
    // TODO 主键隐藏字段，目前写死为ID

    {
        label: 'id',
        field: 'id',
        component: 'Input',
        show: false
    },
    {
        label: '上级区域ID',
        field: 'lastareaid',
        show: false,
        component: 'Input',
    },
    {
        label:"区域名称",
        field: 'areaname',
        show: ({ values }) => {
            const type = values.type;
            return (type == 5 || type == 6) ? false : true
        },
        component: 'ApiSelect',
        render: ({ model, field }) => {
            //渲染自定义组件，以Input为例
            return h(ApiSelect, {
                api: (e) => {
                    let type = 1
                     if(model.type == 5){
                        type = 3
                    }else if(model.type == 6){
                        type = 4
                    }
                    return codeNameInfoListAll(type,model.searchValue) as any
                },
                allowClear: true,
                resultField: 'result',
                labelField: 'nameAndCode',
                valueField: 'nameAndCode',
                showSearch: true,
                value: model.areaname,
                onSearch:(e)=>{
                    model.searchValue = e
                },
                onChange: (e: ChangeEvent) => {
                    if (e == model.areaname) {
                        return
                    }
                    model.areaname = e.split("-")[0]
                    model.areaid = e.split("-")[1]
                },
            });
        },
    },
    {
        label: '区域编码',
        field: 'areaid',
        component: 'Input',
        componentProps:{
            disabled:true
        },
        show: ({ values }) => {
            const type = values.type;
            return (type == 5 || type == 6) ? false : true
        }
    },
    {
        label: '局站名称',
        field: 'sitename',
        show: ({ values }) => {
            const type = values.type;
            return (type == 1 || type == 2 || type == 3 || type == 5 || type == 6) ? false : true
        },
        component: 'ApiSelect',
        render: ({ model, field }) => {
            //渲染自定义组件，以Input为例
            return h(ApiSelect, {
                api: (e) => {
                    return codeNameInfoListAll(2,model.searchValue) as any
                },
                allowClear: true,
                resultField: 'result',
                labelField: 'nameAndCode',
                valueField: 'nameAndCode',
                showSearch: true,
                value: model.sitename,
                onSearch:(e)=>{
                    model.searchValue = e
                },
                onChange: (e: ChangeEvent) => {
                    if (e == model.areaname) {
                        return
                    }
                    model.sitename = e.split("-")[0]
                    model.siteid = e.split("-")[e.split("-").length - 1]
                },
            });
        },
    },
    {
        label: '局站编号',
        field: 'siteid',
        show: ({ values }) => {
            const type = values.type;
            return (type == 1 || type == 2 || type == 3 || type == 5 || type == 6) ? false : true
        },
        component:"Input",
        componentProps:{
            disabled:true
        }
    },
    
    {
        label: '机房名称',
        field: 'roomName',
        show: ({ values }) => {
            const type = values.type;
            return (type == 1 || type == 2 || type == 3 || type == 4 || type == 6) ? false : true
        },
        component: 'ApiSelect',
        render: ({ model, field }) => {
            //渲染自定义组件，以Input为例
            return h(ApiSelect, {
                api: (e) => {
                    let type = 1
                    if(model.type == 4){
                     type = 2
                    }else if(model.type == 5){
                        type = 3
                    }else if(model.type == 6){
                        type = 4
                    }
                    return codeNameInfoListAll(type,model.searchValue) as any
                },
                allowClear: true,
                resultField: 'result',
                labelField: 'nameAndCode',
                valueField: 'nameAndCode',
                showSearch: true,
                value: model.roomName,
                onSearch:(e)=>{
                    model.searchValue = e
                },
                onChange: (e: ChangeEvent) => {
                    if (e == model.mpBigType) {
                        return
                    }
                    model.roomName = e.split("-")[0]
                    model.roomid = e.split("-")[e.split("-").length - 1]
                },
            });
        },
    },
    {
        label: '机房编号',
        field: 'roomid',
        show: ({ values }) => {
            const type = values.type;
            return (type == 1 || type == 2 || type == 3 || type == 4 || type == 6) ? false : true
        },
        component: 'Input',
        componentProps:{
            disabled:true
        }
    },
    
    
];
